package com.example.demo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.dao.IUserDao;
import com.example.demo.entity.User;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class DemoApplicationTests2 {
    @Resource
    private IUserDao userDao;

    QueryWrapper<User> wrapper = new QueryWrapper<>();

    /**
     * 分页查询
     */
    @Test
    void test01() {
        IPage<User> page = new Page<>(2, 2);
        IPage<User> pageResult = userDao.selectPage(page, wrapper.gt("usr_money",2000.0));
        System.out.println("总条数 ------>"+pageResult.getTotal());
        System.out.println("当前页数 ------>"+pageResult.getCurrent());
        System.out.println("当前每页显示数 ------>"+pageResult.getSize());
        System.out.println("总页数 ------>"+(String.valueOf(pageResult.getTotal()%pageResult.getSize()).equals(0)? (int) (pageResult.getTotal() / pageResult.getSize()) : (int) (pageResult.getTotal() / pageResult.getSize())+1));
        pageResult.getRecords().forEach(System.out::println);
    }

}
